﻿using Microsoft.AspNetCore.Mvc;
using Net5ApiAndEfMySql.API.Controllers;
using Net5ApiAndEfMySql.DtoModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VueAndNetCoreEfApi.DtoModel.SystemAdmin;
using VueAndNetCoreEfApi.IService.SystemAdmin;
using VueAndNetCoreEfApi.PoModel.SystemAdmin;

namespace VueAndNetCoreEfApi.Controllers
{
    public class LineController : BaseApiController
    {
        private ILineService _iLineService;
        public LineController(ILineService iLineService)
        {
            _iLineService = iLineService;
        }

        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="sm"></param>
        /// <returns></returns>
        //[HttpPost]

        public ResultModel GetPageList(SearchModel sm)
        {
            ResultModel result = new ResultModel();
            if (sm == null)
            {
                result.code = ResultCode.Error;
                result.mess = "参数错误";
                return result;
            }
            try
            {
                var data = _iLineService.GetPageList(sm);
                data.draw = sm.draw;
                result.code = ResultCode.Ok;
                result.data = data;
                result.mess = "成功!";
            }
            catch (Exception ex)
            {
                result.code = ResultCode.Error;
                result.mess = "错误!";
            }
            return result;
        }
        [HttpPost]
        public ResultModel GetUserInfo(string token)
        {
            ResultModel result = new ResultModel();
            if (string.IsNullOrEmpty(token))
            {
                result.code = ResultCode.Error;
                result.mess = "参数错误";
                return result;
            }
            try
            {
                result.code = ResultCode.Ok;
                result.data = new LineDto() { Token = "test_token" };
                result.mess = "成功!";
            }
            catch (Exception ex)
            {
                result.code = ResultCode.Error;
                result.mess = "错误!";
            }
            return result;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="po"></param>
        /// <returns></returns>

        public ResultModel AddLinePo(LinePo po)
        {
            ResultModel result = new ResultModel();

            try
            {
                var resultData = _iLineService.AddLinePo(po);
                if (resultData)
                {
                    result.code = ResultCode.Ok;
                    result.data = resultData;
                    result.mess = "成功!";
                }
                else
                {
                    result.code = ResultCode.Fail;
                    result.data = resultData;
                    result.mess = "添加失败!";
                }
            }
            catch (Exception ex)
            {
                result.code = ResultCode.Error;
                result.mess = "错误!";
            }
            return result;
        }
        //删除
        public ResultModel DeleteLinePo(int line_id)
        {
            ResultModel result = new ResultModel();
            if (line_id < 0)
            {
                result.code = ResultCode.Error;
                result.mess = "参数错误";
                return result;
            }
            try
            {
                var data = _iLineService.DeleteLinePo(line_id);
                result.code = ResultCode.Ok;
                result.data = data;
                result.mess = "成功!";
            }
            catch (Exception ex)
            {
                result.code = ResultCode.Error;
                result.mess = "错误!";

            }
            return result;
        }
    }
}
